package org.example.weboj.config;

import org.example.weboj.handler.AIStreamWebSocketHandler;
import org.example.weboj.handler.ChatWebSocketHandler;
import org.example.weboj.debug.DebugWebSocketHandler;
import org.example.weboj.handler.SignalingHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    @Autowired
    private AIStreamWebSocketHandler aiStreamWebSocketHandler;

    @Autowired
    private DebugWebSocketHandler debugWebSocketHandler;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        // 注册常规聊天处理器
        registry.addHandler(new ChatWebSocketHandler(), "/chat")
                .setAllowedOrigins("*");  // 允许跨域请求

        registry.addHandler(new SignalingHandler(), "/signal")
                .setAllowedOrigins("*");

        // 注册AI流式聊天处理器
        registry.addHandler(aiStreamWebSocketHandler, "/ai/stream-chat")
                .setAllowedOrigins("*");  // 允许跨域请求

        // 注册调试处理器
        registry.addHandler(debugWebSocketHandler, "/debug")
                .setAllowedOrigins("*");  // 允许跨域请求
    }
}